package com.rh.number.controller;

import com.rh.number.common.ApiResult;
import com.rh.number.dto.FieldResult;
import com.rh.number.dto.FilterOption;
import com.rh.number.dto.FilterParam;
import com.rh.number.service.impl.NumberFilterService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/navigation")
public class NavigationController {
    private final NumberFilterService filterService;

    public NavigationController(NumberFilterService filterService) {
        this.filterService = filterService;
    }

    @PostMapping("/smart-filter")
    public ApiResult<Map<String, List<FilterOption>>> smartFilter(
            @Valid @RequestBody FilterParam param
    ) {
        try {
            Map<String, List<FilterOption>> results = filterService.dynamicFilter(param);
            return ApiResult.success(results);
        } catch (IllegalArgumentException e) {
            return ApiResult.fail(400, e.getMessage());
        }
    }
}
